package acn.spring.backend.spring;

import java.util.List;

import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcDaoSupport;

import acn.spring.backend.ItemDao;
import acn.spring.domain.Item;

public class ItemDaoSpring extends NamedParameterJdbcDaoSupport implements ItemDao {

	@Override
	public List<Item> getAllItems() {
		String sql = "select * from Item";
		List<Item> items = getJdbcTemplate().query(sql, new ItemRowMapper());
		return items;
	}

	@Override
	public Item addItem(Item item) {
		String sql = "insert into Item values (:id, :name, :price)";
		MapSqlParameterSource namedParameters = new MapSqlParameterSource();
		namedParameters.addValue("id", item.getId());
	    namedParameters.addValue("name", item.getName());
	    namedParameters.addValue("price", item.getPrice());
	    getNamedParameterJdbcTemplate().update(sql, namedParameters);
	    return item;
	}

	@Override
	public Item getItemWithId(int id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void deleteItem(int id) {
		// TODO Auto-generated method stub
		
	}

}
